package com.icity.mapper;

import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.icity.controller.content.BrowseSupport;
import com.icity.entity.ChannelStart;
import com.icity.entity.content.Article;
import com.icity.entity.content.ArticleSummary;
import com.icity.entity.content.Catalog;
import com.icity.entity.content.DownRead;
import com.icity.entity.content.DrogonBookInfo;
import com.icity.entity.content.DrogonJournalList;
import com.icity.entity.content.VideoSummary;
import com.icity.entity.content.Videos;

/**
 *
 * @author apple
 */
@Mapper
public interface ContentStatisticalMapper {

	@Select("select * from tbl_video where unique_code = #{unique_code}")
	Videos getVideosByResCode(@Param("unique_code") String unique_code);

	@Select("select * from tbl_article where unique_code = #{unique_code}")
	Article getArticleByResCode(@Param("unique_code") String unique_code);

	@Select("select count(id) from tbl_browse where res_code = #{res_code}")
	int getVideosBrowseByResCode(@Param("res_code") String unique_code);

	@Select("select count(id) from tbl_comment where res_code = #{res_code}")
	int getVideosCommentByResCode(@Param("res_code") String unique_code);

	@Select("select count(id) from tbl_share where res_code = #{res_code}")
	int getVideosShareByResCode(@Param("res_code") String unique_code);

	@Select("select count(id) from tbl_praise where res_code = #{res_code}")
	int getVideosPraiseByResCode(@Param("res_code") String unique_code);

	@Select("SELECT res_code,count(id) as num from tbl_browse where type = #{type} GROUP BY res_code ORDER BY num desc limit 10")
	List<BrowseSupport> getToptenByBrowse(@Param("type") byte type);

	@Select("select a.lend_num,b.book_name from tbl_statistics_bookandma_num a "
			+ "left join tbl_dragon_book_info1 b on a.res_code = b.book_guid "
			+ "where a.res_type = 2 order by a.lend_num desc limit 10")
	List<DownRead> getBookToptenByLendNum();

	@Select("select a.sub_num,b.book_name from tbl_statistics_bookandma_num a "
			+ "left join tbl_dragon_book_info1 b on a.res_code = b.book_guid "
			+ "where a.res_type = 2 order by a.sub_num desc limit 10")
	List<DownRead> getBookToptenByReadNum();

	@Select("select * from tbl_statistics_bookandma_num where res_type = 2")
	List<DownRead> getAllBookList();

	@Select("select a.lend_num,b.name as magazine_name,b.issue as issue from tbl_statistics_bookandma_num a "
			+ "left join tbl_dragon_journal_list b on a.res_code = b.id "
			+ "where a.res_type = 1 order by a.lend_num desc limit 10")
	List<DownRead> getMagazineToptenByLendNum();

	@Select("select a.sub_num,b.name as magazine_name,b.issue as issue from tbl_statistics_bookandma_num a "
			+ "left join tbl_dragon_journal_list b on a.res_code = b.id "
			+ "where a.res_type = 1 order by a.sub_num desc limit 10")
	List<DownRead> getMagazineToptenByReadNum();

	@Select("select * from tbl_statistics_bookandma_num where res_type = 1")
	List<DownRead> getAllMagazineList();

	@Select("select * from tbl_statistics_bookandma_num where res_code = #{res_code}")
	DownRead selectDownReadByCode(@Param("res_code") String res_code);//列表个数

	@Select("select count(id) from tbl_statistics_bookandma_num where res_code = #{res_code}")
	int selectDownReadNumByCode(@Param("res_code") String res_code);//列表个数

	@Select("<script>"
			+"select count(id) from tbl_video where 1 = 1"
			+ "<if test='title != null'>"
			+ " and title like CONCAT('%','${title}','%' ) "
			+ "</if>"
			+ "<if test='cate_name != null'>"
			+ " and cate_name = #{cate_name} "
			+ "</if>"
			+ " </script>")
	int selectCount(Map<Object, Object> map);//列表个数

	@Select("<script>"
			+"select count(id) from tbl_article where 1 = 1"
			+ "<if test='title != null'>"
			+ " and title like CONCAT('%','${title}','%' ) "
			+ "</if>"
			+ "<if test='author_name != null'>"
			+ " and author_name = #{author_name} "
			+ "</if>"
			+ " </script>")
	int selectArticleCount(Map<Object, Object> map);//列表个数

	@Select("<script>"
			+"select count(id) from tbl_statistics_video_summary where 1 = 1"
			+ " </script>")
	int selectVideoSummaryCount(Map<Object, Object> map);//列表个数

	@Select("<script>"
			+"select * "
			+ "from tbl_video where 1 = 1"
			+ "<if test='title != null'>"
			+ " and title like CONCAT('%','${title}','%' ) "
			+ "</if>"
			+ "<if test='cate_name != null'>"
			+ " and cate_name = #{cate_name} "
			+ "</if>"
			+ " ORDER BY  create_time desc"
			+ " limit #{page},#{limit} "
			+ " </script>")
	List<Videos> selectAll(Map<Object, Object> map);//查询视频列表

	@Select("<script>"
			+"select * "
			+ "from tbl_article where 1 = 1"
			+ "<if test='title != null'>"
			+ " and title like CONCAT('%','${title}','%' ) "
			+ "</if>"
			+ "<if test='author_name != null'>"
			+ " and author_name = #{author_name} "
			+ "</if>"
			+ " ORDER BY  create_time desc"
			+ " limit #{page},#{limit} "
			+ " </script>")
	List<Article> selectArticleAll(Map<Object, Object> map);//查询文章列表

	@Select("<script>"
			+"select * "
			+ "from tbl_statistics_video_summary where 1 = 1"
			+ " ORDER BY  date desc"
			+ " limit #{page},#{limit} "
			+ " </script>")
	List<VideoSummary> selectVideoSummaryAll(Map<Object, Object> map);//查询视频统计列表

	@Select("<script>"
			+"select * "
			+ "from tbl_statistics_article_summary where 1 = 1"
			+ " ORDER BY  date desc"
			+ " limit #{page},#{limit} "
			+ " </script>")
	List<ArticleSummary> selectArticleSummaryAll(Map<Object, Object> map);//查询文章统计列表

	@Select("select * from tbl_statistics_catalog where create_date = curdate()")
	Catalog getNowCatalog();

    @Select("select * from tbl_statistics_catalog where create_date between #{startDate} and "
    		+ "#{endDate}  order by create_date")
	List<Catalog> getCatalogByDate(Map<Object, Object> map);

	@Select("<script>"
			+"select * "
			+ "from tbl_dragon_book_info1 where 1 = 1"
			+ " ORDER BY  update_time desc"
			+ " limit #{page},#{limit} "
			+ " </script>")
	List<DrogonBookInfo> getBookList(Map<Object, Object> map);

	@Select("<script>"
			+"select * "
			+ "from tbl_dragon_journal_list where 1 = 1"
			+ " ORDER BY  update_time desc"
			+ " limit #{page},#{limit} "
			+ " </script>")
	List<DrogonJournalList> getMagazineList(Map<Object, Object> map);

	@Select("<script>"
			+"select count(id)"
			+ " from tbl_dragon_book_info1 where 1 = 1"
			+ " </script>")
	int getBookListCount();

	@Select("<script>"
			+"select count(id)"
			+ " from tbl_dragon_journal_list where 1 = 1"
			+ " </script>")
	int getMagazineListCount();

    @Select("select * from tbl_statistics_video_summary where date between #{startDate} and "
    		+ "#{endDate}  order by date")
	List<VideoSummary> getVideoNumList(Map<Object, Object> map);

    @Select("select * from tbl_statistics_article_summary where date between #{startDate} and "
    		+ "#{endDate}  order by date")
	List<ArticleSummary> getArticleNumList(Map<Object, Object> map);

}
